<?
  session_start();

  function fnEncrypt($sValue, $sSecretKey) {
      return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $sSecretKey, $sDecrypted, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
  }

  include(dirname(__FILE__) . "/database.inc.php");
  $db = new database(dirname(__FILE__) . "/streaming.rdb");

  $uname = $_POST['uname'];
  $pword = fnEncrypt($_POST['pword'], "higherglyphics");

  $db->query("SELECT * FROM users WHERE uname = ? AND pword = ?", array($uname, $pword));

  if($db->num_rows > 0){
    $_SESSION['validuser'] = true;
    unset($_SESSION['loginerror']);
  } else {
    unset($_SESSION['validuser']);
    $_SESSION['loginerror'] = "<div style='text-align: center; padding: 10px; border-bottom: 1px solid black; margin-bottom: 10px;'>Invalid username or password. Try again.</div>";
  }
?>

<script type="text/javascript">window.location = "/streaming/admin.php";</script>